✨ BCA JUL24 Batch ✨

Join Our WhatsApp Group

Anukasif Pic

5.1 - Pointers - MCQs

Interactive MCQs Quiz

Test your knowledge with these questions

1. A pointer in C is used to store:

2. Which of the following is the correct way to declare a pointer in C?

3. What does the following statement do: int *ptr;?

4. What is the output of the following code?

int a = 10;
int *p = &a;
printf("%d", *p);

5. What is a null pointer?

6. What is the correct syntax to access the value at the address stored by a pointer p?

7. Which operator is used to get the address of a variable?

8. How much memory is consumed by a pointer on a 64-bit system?

9. If p is a pointer to an integer, what is p + 1?

10. Which of the following is an invalid pointer arithmetic operation?

11. A pointer in C is stored in:

12. What happens if you try to dereference a null pointer?

13. What does int **ptr; represent?

14. Which operator is used to dereference a pointer?

15. What is the output of the following code?

                    int a = 20;
                    int *p = &a;
                    printf("%p", p);
                

16. What is a dangling pointer?

17. Which of the following is the correct way to allocate memory dynamically?

18. Which of the following statements is true about pointer arithmetic?

19. What is the output of the following code?

                    int a = 5;
                    int *p = &a;
                    p++;
                    printf("%d", *p);
                

20. Which of the following is a valid use of a pointer?

21. Which of the following is used to refer to the base address of an array?

22. How do you declare a pointer to an array of 5 integers?

23. What does p = &a; do if a is an array?

24. What is the output of printf("%u", *p); if p is a pointer to an array a[]?

25. Which of the following is true about pointers to functions?

26. How do you declare a pointer to a function that returns an int and takes two int arguments?

27. What is the purpose of the clrscr() function in the example provided?

28. Which of the following is valid syntax for calling a function using a function pointer?

29. What will gets(a) do in the string example provided?

30. Which of the following is true about the pointer p in the string example?

31. In the string example, what will the expression *p return?

32. What does *p += 32 do in the string conversion example?

33. What is the output of the matrix example if the matrix contains only zeros?

34. What does the expression p = &a[0][0]; do in the matrix example?

35. In the matrix example, what will sum = sum + *p; do?

36. What is the correct way to pass a 2D array to a function using pointers?

37. What is a NULL pointer in C?

38. What does the dereference operator (*) do in C?

39. What happens when you increment a pointer in C?

40. What does *p++ mean in pointer arithmetic?

41. What is the correct syntax for declaring a pointer to an array in C?

42. Which of the following is a valid way to initialize a pointer to the first element of an array?

43. What does the expression *(p + 1) represent in pointer arithmetic when p points to the first element of an array?

44. Which of the following statements about arrays and pointers is true?

45. Which operator is used to get the address of the first element of an array?

46. What is the output of the following code?

int arr[] = {1, 2, 3};
int *p = arr;
printf("%d", *(p + 1));

47. Which of the following operations is invalid for array names?

48. Which of the following declares a pointer to a function?

49. If int arr[5] and int *p = arr;, which expression correctly accesses the third element of the array?

50. What is the output of the following code?

int arr[] = {10, 20, 30, 40};
int *p = arr + 2;
printf("%d", *p);

51. Which statement correctly passes an array to a function?

52. In pointer arithmetic, what is the result of subtracting two pointers?

53. What is the size of a pointer on a 64-bit machine?

54. Which of the following is NOT true about pointers and arrays in C?

55. Which of the following correctly accesses the value at the second index of the array using pointer notation?

56. Which of the following is a valid way to declare a pointer to an array of integers?

57. Which of the following is true about the relationship between arrays and pointers?

58. In C, how can you pass an entire array to a function?

59. What is the difference between array and &array[0] in C?

60. What is the output of the following code?

int arr[] = {5, 10, 15};
            int *p = arr;
            p += 2;
            printf("%d", *p);

61. What does the following code snippet do? *pArray1++ = 1;

62. What does the expression *(pArray++) do?

63. What happens if you remove parentheses from the expression *(pArray2 + i)?

64. Which of the following is the correct way to declare an array in C?

65. What is the result of the expression (*pArray)++?

66. What is the difference between *pArray++ and ++*pArray?

67. Which of the following statements is true about pointers in C?

68. What is the value of array[0] after executing the code int array[3] = {1, 2, 3};?

69. Which of the following is a valid use of a pointer?

70. What is the output of the following code? printf("%p", &array[0]);

71. What does arrayName represent in C when dealing with arrays?

72. Which function is commonly used for dynamic memory allocation in C?

73. What is the purpose of free() in C?

74. In C, how is a pointer incremented to traverse an array?

75. Which operator is used to dereference a pointer?

76. What will happen if you increment an array name directly in C?

77. Which function is used to dynamically allocate an array?

78. What is the purpose of *(pArray++) in the context of pointer arithmetic?

79. What is the result of the statement pArray1++?

80. In C, how can you initialize an array and pointer at the same time?

81. What type of argument is passed when an array is supplied to a function in C?

82. What does passing an array to a function in C actually pass?

83. When assigning an array to another variable, what is copied?

84. Which of the following methods can be used to pass an array to a function in C?

85. In the function prototype void traverse1(int size, int arr[]), what does arr[] signify?

86. Which of the following is NOT a valid way to traverse an array in C?

87. What is the output of *array if array is an integer array initialized as int array[5] = {10, 20, 30, 40, 50};?

88. In the function traverse2(int size, int* pArr), how is the array accessed?

89. Which of the following correctly increments a pointer inside a for loop?

90. When passing an array to a function, which notation can be used to access the elements?

91. What does &arr[i] return in the context of array access?

92. What is the main advantage of passing arrays as pointers to functions?

93. Which of the following statements is true about arrays and pointers in C?

94. In the function prototype void traverse3(int size, int arr[]), what does size represent?

95. What is the purpose of using a pointer to an array as a function parameter?

96. Which loop structure is used to traverse the array in the provided examples?

97. What is the output of the following statement: printf("%p", &array);?

98. In the function traverse4(int size, int* pArr), what notation is used to access the array elements?

99. What happens if you try to assign one array to another in C?

100. Which statement is true about the memory allocation of arrays in C?

101. When is it appropriate to use pointer notation instead of array notation?

102. In the function prototype void traverse2(int size, int* pArr), what is the role of pArr?

103. Which of the following is a valid pointer declaration in C?

104. What does the term "pointer arithmetic" refer to?

105. In the context of arrays and pointers, which of the following statements is correct?

106. What will the expression sizeof(array) return for an integer array of size 5?

107. In C, how are multi-dimensional arrays accessed?

108. What is the benefit of passing arrays to functions in C?

109. When using pointers in C, what must you always ensure?

110. What is the primary reason for using function prototypes in C?

111. Which of the following correctly declares a standard 2D array in C?

112. What does the statement int* arrayPtr[3] declare?

113. How are elements accessed in a standard 2D array?

114. Which of the following will correctly initialize a standard 2D array?

115. What is the purpose of the line pInteger = &(arrayStd[0][0]);?

116. In the context of the array of pointers, how do you access the second element of the first sub-array?

117. Which statement is true about the memory layout of a standard 2D array?

118. What is the output of the statement printf("%2d", arrayStd[1][3]); given the standard 2D array is initialized as shown?

119. In the provided code, which of the following will correctly traverse the arrayPtr using pointers?

120. When using pointer arithmetic with a standard 2D array, what is the correct way to increment the pointer?

121. Which of the following is a valid way to declare sub-arrays for the pointer array?

122. Which of the following expressions correctly accesses the third element of the second row of arrayStd?

123. What will happen if you attempt to access an element outside the bounds of the arrayPtr?

124. Which of the following statements correctly initializes the pointer to the first element of the second sub-array?

125. In pointer arithmetic, how do you move to the next sub-array?

126. What will the output of the loop for (int i=0; i<3; i++) { printf("%d", arrayPtr[i][0]); } be given the initial values?

127. How do you declare a pointer to a pointer in the context of an array of pointers?

128. Which of the following is true regarding the access of elements in the arrayStd vs. arrayPtr?

129. Which of the following statements is true regarding the initialization of arrayPtr?

130. In the provided code, what will be the effect of setting #define EXPERIMENT 1?

131. What is a dangling pointer?

132. Which of the following causes a dangling pointer?

133. What happens if you dereference a dangling pointer?

134. How can you prevent a dangling pointer after freeing memory?

135. In the following code, what happens to ptr after free(ptr)?

int *ptr = (int *)malloc(sizeof(int));
            free(ptr);

136. Which of the following statements is true about a pointer that points to a local variable?

137. In the following code, what will happen to str after the inner block ends?

char *str;
            {
                char a = 'A';
                str = &a;
            }

138. What is the output of the following code if str becomes a dangling pointer?

printf("%s", str);

139. Which of the following is a safe practice to avoid dangling pointers?

140. What is the result of attempting to dereference a pointer after freeing its memory?

141. In the context of memory management, which function is used to deallocate memory?

142. What does it mean when a pointer is "wild"?

143. How can the issue of dangling pointers be detected in a program?

144. Which statement is true regarding the lifetime of a pointer?

145. In the provided example, what would be a better approach to handle pointers?

                    int *ptr = (int *)malloc(sizeof(int));
                    free(ptr);
                    ptr = NULL; // Is this a good practice?
                

146. What is the danger of not setting a pointer to NULL after freeing it?

147. Which of the following can help manage memory effectively in C?

148. How does the use of local variables influence dangling pointers?

149. What is the best practice after using free() on a pointer?

150. Why is it important to manage dangling pointers in C?

151. What does a pointer in C hold?

152. Why is it not advisable to return a pointer to a local variable from a function?

153. What will the following function return?

int* fun() { int A = 10; return &A; }

154. In the context of returning pointers, what is the advantage of using static variables?

155. What does the following program print?

#include 
            int* fun() {
                static int A = 10;
                return &A;
            }
            int main() {
                int* p = fun();
                printf("%d\n", *p);
            }

156. What is the purpose of the static keyword in the context of the fun function?

157. What happens to the pointer returned by the fun function if A is not static?

158. Which of the following is true regarding the output of the program when returning a pointer to a static variable?

159. What is the correct way to declare a function that returns a pointer to an integer?

160. How can you correctly return a pointer from a function?

161. What will happen if you try to dereference a pointer to a local variable after the function exits?

162. What does the printf("%p\n", p); statement do in the provided code?

163. Which statement is correct about the lifetime of a static variable?

164. In the context of the second program, what is the output of printf("%p\n", p);?

165. When is it safe to return a pointer from a function?

166. Which function cannot return a pointer?

167. What will happen if the static variable in the fun function is removed?

168. What is the main takeaway when dealing with functions returning pointers in C?

169. Which of the following is NOT a valid way to manage memory with pointers?

170. What is the output of the function fun() if called multiple times without changing its definition?